home *** CD-ROM | disk | FTP | other *** search
/ Champak 114 / Vol 114.iso / games / park_thi.swf / scripts / __Packages / classes / CollisionDetection.as
Encoding:
Text File  |  2010-08-12  |  1.7 KB  |  46 lines

  1. class classes.CollisionDetection
  2. {
  3.    function CollisionDetection()
  4.    {
  5.    }
  6.    static function checkForCollision(p_clip1, p_clip2, p_alphaTolerance, p_scope)
  7.    {
  8.       if(p_alphaTolerance == undefined)
  9.       {
  10.          p_alphaTolerance = 255;
  11.       }
  12.       if(p_scope == undefined)
  13.       {
  14.          p_scope = p_clip2._parent;
  15.       }
  16.       var _loc3_ = p_clip1.getBounds(p_scope);
  17.       var _loc2_ = p_clip2.getBounds(p_scope);
  18.       if(_loc3_.xMax < _loc2_.xMin || _loc2_.xMax < _loc3_.xMin || (_loc3_.yMax < _loc2_.yMin || _loc2_.yMax < _loc3_.yMin))
  19.       {
  20.          return null;
  21.       }
  22.       var _loc1_ = {};
  23.       _loc1_.xMin = Math.max(_loc3_.xMin,_loc2_.xMin);
  24.       _loc1_.xMax = Math.min(_loc3_.xMax,_loc2_.xMax);
  25.       _loc1_.yMin = Math.max(_loc3_.yMin,_loc2_.yMin);
  26.       _loc1_.yMax = Math.min(_loc3_.yMax,_loc2_.yMax);
  27.       var _loc8_ = new flash.display.BitmapData(_loc1_.xMax - _loc1_.xMin,_loc1_.yMax - _loc1_.yMin,false);
  28.       var _loc4_ = p_clip1.transform.matrix;
  29.       _loc4_.tx = p_clip1._x - _loc1_.xMin;
  30.       _loc4_.ty = p_clip1._y - _loc1_.yMin;
  31.       _loc8_.draw(p_clip1,_loc4_,new flash.geom.ColorTransform(1,1,1,1,255,-255,-255,p_alphaTolerance));
  32.       _loc4_ = p_clip2.transform.matrix;
  33.       _loc4_.tx = p_clip2._x - _loc1_.xMin;
  34.       _loc4_.ty = p_clip2._y - _loc1_.yMin;
  35.       _loc8_.draw(p_clip2,_loc4_,new flash.geom.ColorTransform(1,1,1,1,255,255,255,p_alphaTolerance),"difference");
  36.       var _loc6_ = _loc8_.getColorBoundsRect(4294967295,4278255615);
  37.       if(_loc6_.width == 0)
  38.       {
  39.          return null;
  40.       }
  41.       _loc6_.x += _loc1_.xMin;
  42.       _loc6_.y += _loc1_.yMin;
  43.       return _loc6_;
  44.    }
  45. }
  46.